/**
 * 文件上传处理
 */
const express = require('express');
const multer = require('multer');
const fs = require('fs');
const pathLib = require('path');

// 上传缓存目录
var cachesPath = __dirname + "/cache/";

var objMulter = multer({dest: cachesPath});
var server = express();
server.use(objMulter.any());

server.post('/',function (req,res) {
    console.log(req.files);
    // 改文件后缀
    var tempFile = req.files[0];
    // 获取文件后缀
    var fileExName =  pathLib.parse(tempFile.originalname).ext;
    // 修改文件名
    fs.rename(tempFile.path,tempFile.path+fileExName,function (err) {
        if (err) res.send("upLode Err");
        else res.send("file Uplode Ok : "+pathLib.parse(tempFile.path+fileExName).base);
    });
});

server.use("/",function (req,res) {
    res.end("hello");
});

server.listen(3000);
